﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hi_Baidu.Packet.InPacket.TalkInPacket
{
    class Detach_TalkMessagePacket : TalkMessageInPackage
    {
        public Detach_TalkMessagePacket(TalkMessageInPackage inpackage)
            : base(inpackage)
        {
        }

        public override void InitPackage()
        {
            int Offset = 0;
            byte[] UsernameLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, UsernameLength, 0, 4);
            Offset += 4;
            byte[] Username = new byte[BitConverter.ToInt32(UsernameLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Username, 0, Username.Length);
            Offset += Username.Length;
            byte[] FriendNameLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, FriendNameLength, 0, 4);
            Offset += 4;
            byte[] FriendName = new byte[BitConverter.ToInt32(FriendNameLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, FriendName, 0, FriendName.Length);
            Offset += FriendName.Length;
            byte[] SessionLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, SessionLength, 0, 4);
            Offset += 4;
            byte[] Session = new byte[BitConverter.ToInt32(SessionLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Session, 0, Session.Length);
            Offset += Session.Length;
            byte[] DetachMessageLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, DetachMessageLength, 0, 4);
            Offset += 4;
            byte[] DetachMessage = new byte[BitConverter.ToInt32(DetachMessageLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, DetachMessage, 0, DetachMessage.Length);
            Offset += DetachMessage.Length;
            byte[] PackageId = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, PackageId, 0, 4);
            Offset += 4;
            byte[] TotalPackageCount = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, TotalPackageCount, 0, 4);
            Offset += 4;


            this.DIC_CONTENT.Add("USERNAME", Username);
            this.DIC_CONTENT.Add("FRIENDUSERNAME", FriendName);
            this.DIC_CONTENT.Add("SESSION", Session);
            this.DIC_CONTENT.Add("DETACHMESSAGE", DetachMessage);
            this.DIC_CONTENT.Add("PACKAGEID", PackageId);
            this.DIC_CONTENT.Add("TOTALCOUNT", TotalPackageCount);
        }

        /// <summary>
        ///     获得好友用户名
        /// </summary>
        /// <returns></returns>
        public String GetFriendName()
        {
            return Encoding.Default.GetString(this.DIC_CONTENT["USERNAME"]);
        }

        /// <summary>
        ///     获得当前会话ID
        /// </summary>
        /// <returns></returns>
        public String GetSession()
        {
            return Encoding.Default.GetString(this.DIC_CONTENT["SESSION"]);
        }

        /// <summary>
        ///     获得当前封包片ID
        /// </summary>
        /// <returns></returns>
        public int GetPackageId()
        {
            return BitConverter.ToInt32(this.DIC_CONTENT["PACKAGEID"], 0);
        }

        /// <summary>
        ///     获得当前封包总封包片数量
        /// </summary>
        /// <returns></returns>
        public int GetTotalPackageCount()
        {
            return BitConverter.ToInt32(this.DIC_CONTENT["TOTALCOUNT"], 0);
        }

        /// <summary>
        ///     获得当前封包片所包含的数据
        /// </summary>
        /// <returns></returns>
        public byte[] GetDetachMessage()
        {
            return this.DIC_CONTENT["DETACHMESSAGE"];;
        }
    }
}
